package com.hnkywl.sts.service.htgl;

import com.hnkywl.sts.dao.htgl.BzjckllDao;
import com.hnkywl.sts.entity.htgl.Bzjckll;
import com.hnkywl.sts.service.sys.YgService;
import com.hnkywl.sts.util.EasyuiAdapter;
import net.ruixin.orm.hibernate.OrderBy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * Created by ccr on 2014/4/24.
 */
@Service
public class BzjckllService {
    private BzjckllDao bzjckllDao;

    public String bzjckllList(){
        List<Bzjckll> grid = bzjckllDao.findAll(new OrderBy[]{new OrderBy("rq", OrderBy.OrderType.DESC)});
        return EasyuiAdapter.getJsonForDataGrid(grid, grid.size(), "id","gs.jc", "rq", "ckll", "lastUpdated","createUser.xm");
    }

    @Transactional
    public void save(Bzjckll bzjckll){
        bzjckll.setCreateUser(YgService.getCurrentYg());
        bzjckll.setDateCreated(new Date());
        bzjckll.setLastUpdated(new Date());
        bzjckllDao.save(bzjckll);
    }

    @Transactional
    public void delete(Bzjckll bzjckll){
        bzjckll = bzjckllDao.get(bzjckll.getId());
        bzjckll.setDeleted(1);
        bzjckll.setLastUpdated(new Date());
        bzjckllDao.save(bzjckll);
    }

    @Autowired
    public void setBzjckllDao(BzjckllDao bzjckllDao) {
        this.bzjckllDao = bzjckllDao;
    }
}
